package com.coin.controller;

import com.coin.domain.Account;
import com.coin.model.R;
import com.coin.service.AccountService;
import com.coin.vo.UserTotalAccountVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: 李 力
 * @Date: 2025/6/19
 * @Description: com.coin.controller
 * @version: 1.0
 */
@RestController
@RequestMapping("/account")
@Api(tags = "资产服务的控制器")
public class AccountController {

    @Autowired
    private AccountService accountService;

    /**
     * @Description: 获取当前用户的货币的资产情况
     * @Author: 李 力
     * @Date: 2025/6/19
     * @Param:
     * @return: R
     */
    @GetMapping("/{coinName}")
    @ApiOperation(value = "获取当前用户的货币的资产情况")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coinName", value = "货币的名称")
    })
    public R<Account> getUserAccount(@PathVariable("coinName") String coinName) {
        Long userId = Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        Account account = accountService.findByUserAndCoin(userId, coinName);
        return R.ok(account);
    }

    @GetMapping("/total")
    public R<UserTotalAccountVo> getTotal() {
        Long userId = Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        UserTotalAccountVo totalAccountVo = accountService.getTotal(userId);
        return R.ok(totalAccountVo);
    }
}
